package com.gdyx.app.web.svc.impl;

import com.gdyx.app.web.dao.MpsOrgUserDao;
import com.gdyx.app.web.model.MpsOrgUser;
import com.gdyx.app.web.svc.MpsOrgUserSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class MpsOrgUserSvcImpl implements MpsOrgUserSvc {
    @Autowired
    MpsOrgUserDao dao;

    @Override
    public void save(MpsOrgUser o) {
        dao.save(o);
    }

    @Override
    public void delete(String id) {
        dao.delete(id);
    }

    @Override
    public void update(MpsOrgUser o) {
        dao.update(o);
    }

    @Override
    public int count(Map<String, Object> map) {
        return dao.count(map);
    }

    @Override
    public List<MpsOrgUser> findMpsOrgUsers(Map<String, Object> map) {
        return dao.findMpsOrgUsers(map);
    }

    @Override
    public void repulse(String id) {
        MpsOrgUser mpsOrgUsersById = dao.findMpsOrgUsersById(id);
        mpsOrgUsersById.setOrgchk(3);
        dao.update(mpsOrgUsersById);
    }

    @Override
    public void applySave(String uid, String orgId, String descr) {
        MpsOrgUser mpsOrgUser=new MpsOrgUser();
        mpsOrgUser.setId(UUID.randomUUID().toString().toUpperCase().trim());
        mpsOrgUser.setUserId(uid);
        mpsOrgUser.setOrgId(orgId);
        mpsOrgUser.setDescr(descr);
        mpsOrgUser.setUserchk(0);
        mpsOrgUser.setOrgchk(2);
        dao.save(mpsOrgUser);
    }

    @Override
    public void ApplySave(String id) {
        MpsOrgUser mpsOrgUsersById = dao.findMpsOrgUsersById(id);
        mpsOrgUsersById.setOrgchk(0);
        dao.update(mpsOrgUsersById);
    }

    @Override
    public void invite(String id,String orgId) {
        MpsOrgUser mpsOrgUser=new MpsOrgUser();
        mpsOrgUser.setId(UUID.randomUUID().toString().toUpperCase().trim());
        mpsOrgUser.setUserId(id);
        mpsOrgUser.setOrgId(orgId);
        mpsOrgUser.setOrgchk(0);
        mpsOrgUser.setUserchk(2);
        dao.save(mpsOrgUser);
    }

    @Override
    public MpsOrgUser findMpsOrgUsersByIdAndOrgId(String orgId, String userId) {
        return dao.findMpsOrgUsersByIdAndOrgId(orgId,userId);
    }


    @Override
    public List<MpsOrgUser> findMpsOrgUsersByUid(String id) {
        return dao.findMpsOrgUsersByUid(id);
    }

    @Override
    public List<MpsOrgUser> findMpsOrgUsersByOid(String id) {
        return dao.findMpsOrgUsersByOid(id);
    }

    @Override
    public MpsOrgUser findMpsOrgUsersById(String id) {
        return  dao.findMpsOrgUsersById(id);
    }
}
